package com.zzxy.spring34.factory;

import com.zzxy.spring34.aspect.MyAspect;
import com.zzxy.spring34.dao.impl.StudentDaoImpl;
import com.zzxy.spring34.service.impl.StudentServiceImpl;

import java.lang.reflect.Method;

public class MyBeanFactoryCglib {
    public static StudentDaoImpl creatStudentServiceProxy(){
        StudentServiceImpl studentService = new StudentServiceImpl();
        MyAspect aspect = new Enhancer();
        Enhancer enhancer = new Enhancer();
        enhancer.setCallback(new MethodInterceptor(){
            @Override
            public Object intercept(Object o, Method method,object[] objects,MethodProxy) throws Throwable {
                aspect.before();
                Object obj = methodProxy.invokeSuper(o,objects);
                aspect.after();
                return obj;
            }
        });
        return (StudentDaoImpl) enhancer.create();

    }
}
